/**$Licence:
 *  Copyright (C) 2008 - 2012 www.java1995.com . All rights reserved.
 *
 *  Use this however/wherever you like, just don't blame me if it breaks anything.
 *
 */

package com.blazemina.container;

import com.blazegame.logging.Logger;
import com.blazegame.logging.LoggerFactory;
import com.blazemina.command.DefaultJavaCommandFactory;
import com.blazemina.config.BlazeminaConfigManager;
import com.blazemina.exception.BlazeminaRuntimeException;
import com.blazemina.executor.BlazeminaExecutors;
import com.blazemina.executor.RouteHelper;
import com.blazemina.executor.RouteInfo;
import com.blazemina.CommandContext;

/**
 * @author JackChu
 * @version 1.0.0 2012-1-12 下午8:18:38
 */
public class DefaultRequestProcessor implements RequestProcessor {

	private final static Logger log = LoggerFactory
			.getLogger(DefaultJavaCommandFactory.class);

	@Override
	public final void processor(CommandContext commandContext) {
		BlazeminaExecutors blazeminaExecutors = BlazeminaConfigManager.me()
				.getBlazeminaExecutors();
		RouteInfo routeInfo = null;
		if (blazeminaExecutors.isThreadPool()) {
			RouteHelper routeHelper = BlazeminaConfigManager.me()
					.getRouteHelper();
			if (routeHelper == null) {
				throw new BlazeminaRuntimeException("route help is initalize?");
			}
			routeInfo = routeHelper.getRouteInfo(commandContext);
		}
		blazeminaExecutors.execute(commandContext, routeInfo);
	}

}
